package com.whmnx.my.ui.viewmodel;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.whmnx.base.bean.BagListBean;
import com.whmnx.base.bean.BaseBean;
import com.whmnx.base.constants.Constants;
import com.whmnx.base.http.CallBack;
import com.whmnx.base.http.HttpClient;
import com.whmnx.base.view.CommonDialog2;
import com.whmnx.my.R;

import java.util.HashMap;
import java.util.Map;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.SPUtils;
import me.goldze.mvvmhabit.utils.ToastUtils;

/**
 * author : huang
 * date   : 2020/9/16 0016 10:03
 * version: 1.0
 * @author Administrator
 */
public class BodouItemViewModel extends ItemViewModel {

    Bodou1Model viewModel;

    public ObservableField<BagListBean> entity = new ObservableField<>();

    public ObservableField<String> ValiDAy = new ObservableField<>("");
    public ObservableField<String> ValidDay = new ObservableField<>("");
    //
    public ObservableField<String> GainMoney = new ObservableField<>("");
    public ObservableField<String> ExChangeBeanNum = new ObservableField<>("");
    public ObservableField<String> HaveNum = new ObservableField<>("");

    public String imgUrl;


    public BodouItemViewModel(@NonNull Bodou1Model viewModel, BagListBean bagListBean) {
        super(viewModel);
        this.viewModel = viewModel;
        this.entity.set(bagListBean);
        ValiDAy.set(entity.get().getTimes() + "次");
        ValidDay.set(entity.get().getValiDAy() + "天");
        GainMoney.set(entity.get().getGainMoney() + "");
        ExChangeBeanNum.set(entity.get().getExChangeBeanNum() + "");
        HaveNum.set("1/" + entity.get().getHaveNum() + "");
        this.imgUrl = Constants.HOST + entity.get().getHeadImg();
    }


    public BindingCommand OnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            String s2 = "是否兑换播豆";
            new CommonDialog2(viewModel.mFragment.getActivity(), R.style.dialog, s2,"", (dialog, confirm) -> {
                if (confirm) {
                    Map<String, Object> params = new HashMap<>();
                    params.put("BeanBagId",entity.get().getId());
                    params.put("UserId", SPUtils.getInstance().getString(Constants.USERID));
                    HttpClient.get(viewModel.mFragment.getActivity(), Constants.CONVERTBEANBAG, params,new CallBack<BaseBean>() {
                        @Override
                        public void onSuccess(BaseBean bagListBeans) {
                            ToastUtils.showShort("兑换成功");
                        }
                    });
                }
                dialog.dismiss();
            }).show();
        }
    });
}
